import { request } from '@/plugins/http';

export const apiSystemUsers = {
  // 获取管理数据
  getList: () => {
    return request('/admin/system/users');
  },
  // 获取管理员信息
  getInfo: async (id: number): Promise<API.Users> => {
    const resp = await request(`/admin/system/users/${id}`);
    return {
      ...resp.data,
    };
  },
  // 新增管理员
  createUsers: (data: API.FormUserCreate[]) => {
    return request('/admin/system/users', {
      method: 'post',
      data: {
        users: data,
      },
    });
  },
  // 修改管理员信息
  editInfo: (data: API.Users) => {
    return request(`/admin/system/users/${data.id}`, {
      method: 'put',
      data,
    });
  },
  // 删除管理员
  delete: (ids: number[]) => {
    return request(`/admin/system/users/${ids.join(',')}`, {
      method: 'delete',
    });
  },
  // 获取绑定的角色
  getRoles: async (id: number): Promise<API.UserRole[]> => {
    const resp = await request(`/admin/system/users/${id}/roles`);
    return resp.data.items;
  },
};
